package com.sky.mapper;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * ClassName: ShoppingCartMapper
 * Package: com.sky.mapper
 * Description:
 *
 * @Author 臧洁
 * @Create 2025/4/10 12:33
 * @Version 1.0
 */
@Mapper
public interface ShoppingCartMapper {
    /**
     * 动态条件查询
     * @param shoppingCart
     * @return
     */
    List<ShoppingCart> list(ShoppingCart shoppingCart);

    /**
     * 根据id修改商品数量
     * @param shoppingCart
     */
    @Update("update sky_take_out.shopping_cart set number=#{number} where id =#{id}")
    void updateNumberById(ShoppingCart shoppingCart);

    /**
     * 插入购物车数据
     * @param shoppingCart
     */
    @Insert("insert into sky_take_out.shopping_cart (name, image, user_id, dish_id, setmeal_id, dish_flavor, amount, create_time) VALUES " +
            "(#{name},#{image},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{amount},#{createTime})")
    void insert(ShoppingCart shoppingCart);

    /**
     * 清空购物车
     * @param userId
     */
    @Delete("delete from sky_take_out.shopping_cart where user_id=#{userId}")
    void delete(Long userId);

    /**
     * 减少购物车中的dish数据
     * @param shoppingCartDTO
     */
    @Delete("delete from sky_take_out.shopping_cart where dish_id=#{dishId} and dish_flavor=#{dishFlavor}")
    void deleteDish(ShoppingCartDTO shoppingCartDTO);

    /**
     * 减少购物车中套餐
     * @param shoppingCartDTO
     */
    @Delete("delete from sky_take_out.shopping_cart where setmeal_id =#{setmealId}")
    void deleteSetmeal(ShoppingCartDTO shoppingCartDTO);

    /**
     * 删除购物车中数量为1的商品
     * @param id
     */
    @Delete("delete from sky_take_out.shopping_cart where id=#{id}")
    void deleteById(Long id);

    /**
     * 将购物车对象批量添加到数据库
     * @param shopCartList
     */
    void insertBatch(List<ShoppingCart> shopCartList);
}
